# -*- coding: utf-8 -*-
def f(s):
    l=[]
    startIdx=0
    while s.find('[', startIdx) != -1:
        startIdx = s.index('[', startIdx)
        endIdx = s.index(']', startIdx)
        #print s[startIdx+1:endIdx]
        l.append(s[startIdx+1:endIdx])
        startIdx = endIdx
    
    return l

shous = raw_input()
yans = raw_input()
kous = raw_input()

shou_list = f(shous)
yan_list = f(yans)
kou_list = f(kous)

K = int(raw_input())
while K>0:
    try:
        leftshou,leftyan,kou,rightyan,rightshou = map(int, raw_input().strip().split(' '))
        if leftshou < 1:
            raise
        if leftyan < 1:
            raise
        if kou < 1:
            raise
        if rightyan < 1:
            raise
        if rightshou < 1:
            raise
        #print leftshou, leftyan, kou, rightyan, rightshou
        output=[]
        output.append(shou_list[leftshou-1])
        output.append('(')
        output.append(yan_list[leftyan-1])
        output.append(kou_list[kou-1])
        output.append(yan_list[rightyan-1])
        output.append(')')
        output.append(shou_list[rightshou-1])
        print ''.join(output)
    except:
        print r'Are you kidding me? @\/@'
    K-=1